package com.wn55.hrms.web.controller;


import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.Course;
import com.wn55.hrms.entity.Implementation;
import com.wn55.hrms.service.CourseService;
import com.wn55.hrms.service.ImplementationService;
import com.wn55.hrms.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author z
 */
@RestController
@RequestMapping("course")
@Api(value = "此接口用于操作培训课程功能")
public class CourseController {

    @Autowired
    CourseService courseService;


    @GetMapping("/courseList")
    @ApiOperation(value = "条件分页查询培训课程")

    public ResultResponse<PageInfo<Course>> list(
            @RequestParam(value = "now",defaultValue = "1") Integer now ,
            @RequestParam(value = "size",defaultValue = "2")Integer size,
            String name){
        ResultResponse<PageInfo<Course>> result = null;

        try {
            PageInfo<Course> pageInfo =courseService.courseList(now,size,name);
            result = new ResultResponse<>(200,"查询培训课程成功!",pageInfo);
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"查询培训课程失败!");
        }
        return result ;
    }



    @PutMapping("/modify")
    @ApiOperation(value = "修改培训课程")

    public ResultResponse<Void> modify(@RequestBody Course course){
        ResultResponse<Void> result = null;

        try {

            courseService.modify(course);
            result = new ResultResponse<>(200,"修改培训课程成功!");
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"修改培训课程失败!");
        }
        return result ;
    }



    @PostMapping("/add")
    @ApiOperation(value = "添加培训课程")

    public ResultResponse<Void> add(@RequestBody Course course){
        ResultResponse<Void> result = null;


        try {
            course.setIsDelete(0);

            courseService.add(course);
            result = new ResultResponse<>(200,"添加培训课程成功!");
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"添加培训课程失败!");
        }
        return result ;
    }


    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除课程")

    public ResultResponse<Void> del(@PathVariable("id") String id){
        ResultResponse<Void> result = null;

        try {
            courseService.removeBykey(id);
            result = new ResultResponse<>(200,"删除培训课程成功!");
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(202,"删除培训课程失败!");
        }
        return result ;
    }



}
